home *** CD-ROM | disk | FTP | other *** search
-
-
-
- Tcl_CreateCommand Tcl Command Language Library Tcl_CreateCommand
-
-
-
- _________________________________________________________________
-
- NNAAMMEE
- Tcl_CreateCommand - define an application-specific command
- binding
-
- SSYYNNOOPPSSIISS
- ##iinncclluuddee <<ttccll..hh>>
-
- TTccll__CCrreeaatteeCCoommmmaanndd(_i_n_t_e_r_p, _c_m_d_N_a_m_e, _p_r_o_c, _c_l_i_e_n_t_D_a_t_a, _d_e_l_e_t_e_P_r_o_c)
-
- AARRGGUUMMEENNTTSS
- Tcl_Interp *_i_n_t_e_r_p (in) Interpreter in
- which to create new
- command.
-
- char *_c_m_d_N_a_m_e (in) Name of new com-
- mand.
- Tcl_CreateCommand
- makes a copy of
- this value for its
- own use.
-
- int (*_p_r_o_c)() (in) Implementation of
- new command: _p_r_o_c
- will be called
- whenever _c_m_d_N_a_m_e is
- invoked as a com-
- mand.
-
- ClientData _c_l_i_e_n_t_D_a_t_a (in) Arbitrary one-word
- value to pass to
- _p_r_o_c and
- _d_e_l_e_t_e_P_r_o_c.
-
- void (*_d_e_l_e_t_e_P_r_o_c)() (in) Procedure to call
- before _c_m_d_N_a_m_e is
- deleted from the
- interpreter; allows
- for command-
- specific cleanup.
- If NULL, then no
- procedure is called
- before the command
- is deleted.
-
- _________________________________________________________________
-
-
- DDEESSCCRRIIPPTTIIOONN
- TTccll__CCrreeaatteeCCoommmmaanndd defines a new command in _i_n_t_e_r_p and asso-
- ciates it with procedure _p_r_o_c such that whenever _c_m_d_N_a_m_e is
- invoked as a Tcl command (via a call to TTccll__EEvvaall) the Tcl
- interpreter will call _p_r_o_c to process the command. If there
-
-
-
- Sprite v.1.0 Printed: February 28, 1990 1
-
-
-
-
-
-
- Tcl_CreateCommand Tcl Command Language Library Tcl_CreateCommand
-
-
-
- is already a command _c_m_d_N_a_m_e associated with the inter-
- preter, it is deleted. _P_r_o_c should have the following
- structure:
- int
- proc(_c_l_i_e_n_t_D_a_t_a, _i_n_t_e_r_p, _a_r_g_c, _a_r_g_v)
- ClientData _c_l_i_e_n_t_D_a_t_a;
- Tcl_Interp *_i_n_t_e_r_p;
- int _a_r_g_c;
- char *_a_r_g_v[];
- {
- }
- The _c_l_i_e_n_t_D_a_t_a and _i_n_t_e_r_p parameters are copies of the
- _c_l_i_e_n_t_D_a_t_a and _i_n_t_e_r_p arguments given to TTccll__CCrreeaatteeCCoommmmaanndd.
- Typically, _c_l_i_e_n_t_D_a_t_a points to an application-specific data
- structure that describes what to do when the command pro-
- cedure is invoked. _A_r_g_c and _a_r_g_v describe the arguments to
- the command, _a_r_g_c giving the number of arguments (including
- the command name) and _a_r_g_v giving the values of the argu-
- ments as strings. The _a_r_g_v array will contain _a_r_g_c+1
- values; the first _a_r_g_c values point to the argument strings,
- and the last value is NULL.
-
- _P_r_o_c must return an integer code that is either TTCCLL__OOKK,
- TTCCLL__EERRRROORR, TTCCLL__RREETTUURRNN, TTCCLL__BBRREEAAKK, or TTCCLL__CCOONNTTIINNUUEE. See the
- Tcl overview man page for details on what these codes mean.
- Most normal commands will only return TTCCLL__OOKK or TTCCLL__EERRRROORR.
- In addition, _p_r_o_c must set _i_n_t_e_r_p->_r_e_s_u_l_t to point to a
- string value; in the case of a TTCCLL__OOKK return code this gives
- the result of the command, and in the case of TTCCLL__EERRRROORR it
- gives an error message. The TTccll__RReettuurrnn procedure provides
- an easy interface for setting the return value; for com-
- plete details on how the _i_n_t_e_r_p->_r_e_s_u_l_t field is managed,
- see the TTccll__IInntteerrpp man page. Before invoking a command pro-
- cedure, TTccll__EEvvaall sets _i_n_t_e_r_p->_r_e_s_u_l_t to point to an empty
- string, so simple commands can return an empty result by
- doing nothing at all.
-
- The contents of the _a_r_g_v array are copies made by the Tcl
- interpreter for the use of _p_r_o_c. _P_r_o_c may alter any of the
- strings in _a_r_g_v. However, the _a_r_g_v array is recycled as
- soon as _p_r_o_c returns, so _p_r_o_c must not set _i_n_t_e_r_p->_r_e_s_u_l_t to
- point anywhere within the _a_r_g_v values (call Tcl_Return with
- status TTCCLL__VVOOLLAATTIILLEE if you want to return something from the
- _a_r_g_v array).
-
- _D_e_l_e_t_e_P_r_o_c will be invoked when (if) _c_m_d_N_a_m_e is deleted.
- This can occur through a call to TTccll__DDeelleetteeCCoommmmaanndd or
- TTccll__DDeelleetteeIInntteerrpp, or by replacing _c_m_d_N_a_m_e in another call to
- Tcl_CreateCommand. _D_e_l_e_t_e_P_r_o_c is invoked before the command
- is deleted, and gives the application an opportunity to
- release any structures associated with the command.
- _D_e_l_e_t_e_P_r_o_c should have the following form:
-
-
-
- Sprite v.1.0 Printed: February 28, 1990 2
-
-
-
-
-
-
- Tcl_CreateCommand Tcl Command Language Library Tcl_CreateCommand
-
-
-
- void
- deleteProc(_c_l_i_e_n_t_D_a_t_a)
- ClientData _c_l_i_e_n_t_D_a_t_a;
- {
- }
- The _c_l_i_e_n_t_D_a_t_a argument will be the same as the _c_l_i_e_n_t_D_a_t_a
- argument passed to TTccll__CCrreeaatteeCCoommmmaanndd.
-
-
- KKEEYYWWOORRDDSS
- bind, command, create, interpreter
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sprite v.1.0 Printed: February 28, 1990 3
-
-
-
-